package com.ds.common.route.agent;

import com.ds.common.nacos.NacosConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

import java.util.Optional;

@Configuration
@Slf4j
public class AgentService extends NacosConfig<AgentList> {
    @Override
    protected String getDataId() {
        return "agent_list";
    }

    @Override
    protected String getGroupId() {
        return "route_center";
    }

    @Override
    protected Class<AgentList> getClassType() {
        return AgentList.class;
    }

    public Agent findAgentByDomain(String domain) {
        return Optional.ofNullable(getValue()).map(x -> x.agentMapByDomain.get(domain)).orElse(Agent.DEFAULT);
    }

    public Agent getDefaultAgent() {
        return Agent.DEFAULT;
    }
}
